Create an array from mysql with column names and values [on hold]
Posted
by
ScaZ
on Programmers
See other posts from Programmers
or by ScaZ
Published on 2013-11-07T21:04:32Z
Indexed on
2013/11/07
22:18 UTC
Read the original article
Hit count: 236
i'm trying to create an array with PHP and MySQL, but i always get errors.
The code i'm using
function db_listar_usuarios(){
$link=db_connect();
$query = "select * from usuarios" or die("Problemas en el select: " . mysqli_error($link));
$result = $link->query($query);
while($row = mysqli_fetch_assoc($result)) {
$row['nombre'] . array(;
foreach ($row as $col => $val) {
$col => $val;
}
}
}
And what I want to create with this code is:
array(
'john' => array('address' => 'st 123', 'age' => '25', 'surname' => 'doe'),
'ane' => array('address' => 'av 456', 'age'=> '32', 'surname' => 'smith'),
);
To use then like something like this:
private $contacts = db_listar_usuarios();
I use 2 files: functions.php and server.php
server.php is a downloaded file example to do a REST API.
Here are both of them.
server.php -> pastebin.com/5j54m1Mz
functions.php -> pastebin.com/N7jMhSBa
Thank you in advance!
© Programmers or respective owner